import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import login from '../views/Login.vue'
Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/Home.vue'),
    children:[
      {
        path:"/",
        name:"Commodity",
        component:() => import("../views/children/commodity.vue")
      },
      {
        path:"/order",
        name:"Order",
        component:() => import("../views/children/order.vue")
      },{
        path:"/user",
        name:"User",
        component:() => import("../views/children/user.vue")
      },{
        path:"/menu",
        name:"Menu",
        component:() => import("../views/children/menu.vue")
      },{
        path:"/role",
        name:"Role",
        component:() => import("../views/children/role.vue")
      },{
        path:"/company",
        name:"Company",
        component:() => import("../views/children/company.vue")
      }
    ]  
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  var statuss=localStorage.getItem("token")
  if(statuss){
    next()
  }else{
    if(to.path=='/login'){
      next()
    }else{
      next("/login")
    }
  }
})

export default router
